<template>
	<view>
		<u-empty text="暂无数据" mode="list" v-if="colects.length==0"></u-empty>
		<collect-list :collects="colects" @del="delData" v-else></collect-list>
	</view>
</template>

<script>
	import {
		myCollects,
		uncollectUrl
	} from '@/api/constant.js'
	export default {
		data() {
			return {
				index: 0,
				colects: []
			}
		},
		
		onShow() {
			this.fetLovesList()
		},
		methods: {
			async fetLovesList() {
				let res = await this.$httpGet(`${myCollects}${this.index}/json`)
				this.colects = res.data.datas
				console.log(res.data.datas);
			},
			async delData(index, id) {

				let res = await this.$httpPost(`${uncollectUrl}/${id}/json`)

				if (res.errorCode == 0) {
					uni.showToast({
						title: '取消收藏成功！'
					})
					this.colects.splice(index, 1)
				}

			}
		}
	}
</script>

<style>

</style>
